package svc

import (
	"jgt-oper/src/bll"
	"jgt-oper/src/context"
)

// Employee 服务平台 企业员工管理
type Employee struct {
	EmployeeBll *bll.EmployeeBll `inject:""`
	UserBll     *bll.User        `inject:""`
}

// QueryPage 查询分页
func (a *Employee) QueryPage(ctx *context.Context) error {
	ctx.WriteOperateLog("Employee.QueryPage", "服务平台-企业人员管理-查询人员列表数据")
	params := make(map[string]interface{}, 0)
	params["pageIndex"] = ctx.GetPageIndex()
	params["pageSize"] = ctx.GetPageSize()
	params["user_id"] = ctx.GetUserID()
	params["nick_name"] = ctx.Query("nick_name")
	params["real_name"] = ctx.Query("real_name")
	params["tel"] = ctx.Query("tel")
	params["gender"] = ctx.Query("gender")
	params["user_type"] = ctx.Query("user_type")
	params["start_time"] = ctx.Query("start_time")
	params["end_time"] = ctx.Query("end_time")
	total, listEmployee, err := a.EmployeeBll.QueryPage(params)
	if err != nil {
		return ctx.ResErrBadRequest(err)
	}
	result := map[string]interface{}{
		"list": listEmployee,
		"pagination": map[string]interface{}{
			"total":    total,
			"current":  params["pageIndex"],
			"pageSize": params["pageSize"],
		},
	}
	return ctx.ResSuccess(result)
}

// QueryDetail 查询详情
func (a *Employee) QueryDetail(ctx *context.Context) error {
	ctx.WriteOperateLog("Employee.QueryDetail", "服务平台-企业人员管理-查询人员详情数据")
	userDetail, err := a.EmployeeBll.QueryDetail(ctx.Param("id"))
	if err != nil {
		return ctx.ResErrBadRequest(err)
	}
	return ctx.ResSuccess(userDetail)
}

// CancelAuth 取消认证
func (a *Employee) CancelAuth(ctx *context.Context) error {
	ctx.WriteOperateLog("Employee.CancelAuth", "服务平台-员工管理-取消认证")
	err := a.UserBll.CancelAuth(ctx.Param("id"))
	if err != nil {
		return ctx.ResErrInternalServer(err)
	}
	return ctx.ResOK()
}
